/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Enter_frame.java
 *
 * Created on 15.02.2012, 19:58:09
 */

package pazi_laba1;

import java.awt.Color;

/**
 *
 * @author Mike
 */
public class Enter_frame extends javax.swing.JFrame {

    /** Creates new form Enter_frame */
    public Enter_frame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jTextField_Log = new javax.swing.JTextField();
        jPasswordField = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAutoRequestFocus(false);

        jButton2.setText("GO!");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField_Log.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
        jTextField_Log.setForeground(new java.awt.Color(255, 51, 0));
        jTextField_Log.setText("Введите логин");
        jTextField_Log.setToolTipText("Введите логин");
        jTextField_Log.setCaretColor(new java.awt.Color(204, 51, 0));
        jTextField_Log.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_LogActionPerformed(evt);
            }
        });
        jTextField_Log.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextField_LogFocusGained(evt);
            }
        });

        jPasswordField.setForeground(new java.awt.Color(255, 0, 204));
        jPasswordField.setEchoChar((char)0);
        jPasswordField.setText("Введите пароль");
        jPasswordField.setToolTipText("Enter password");
        jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jPasswordFieldFocusGained(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(149, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPasswordField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_Log, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                .addGap(140, 140, 140))
            .addGroup(layout.createSequentialGroup()
                .addGap(175, 175, 175)
                .addComponent(jButton2)
                .addContainerGap(174, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addComponent(jTextField_Log, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49)
                .addComponent(jButton2)
                .addContainerGap(80, Short.MAX_VALUE))
        );

        jTextField_Log.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
      
      if(new Auth_handler().Auth(jTextField_Log.getText(),jPasswordField.getText()).equals("admin_true")){
      new Main_frame_admin().setVisible(true);setVisible(false);

        }
      if(new Auth_handler().Auth(jTextField_Log.getText(),jPasswordField.getText()).equals("new_pass")){

      }
      if(new Auth_handler().Auth(jTextField_Log.getText(),jPasswordField.getText()).equals("true")){
      new Main_frame_user().setVisible(true);setVisible(false);
      }
      else{flag++;
      System.out.println(flag);
      if(flag==3){System.exit(0);}
      }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField_LogFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField_LogFocusGained
        // TODO add your handling code here:
        jTextField_Log.setForeground(Color.black);
        jTextField_Log.setText("");
    }//GEN-LAST:event_jTextField_LogFocusGained

    private void jTextField_LogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_LogActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_LogActionPerformed

    private void jPasswordFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPasswordFieldFocusGained
        // TODO add your handling code here:
        jPasswordField.setEchoChar('$');
        jPasswordField.setForeground(Color.black);
        jPasswordField.setText("");
    }//GEN-LAST:event_jPasswordFieldFocusGained

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Enter_frame().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JPasswordField jPasswordField;
    private javax.swing.JTextField jTextField_Log;
    // End of variables declaration//GEN-END:variables
    private int flag;
}
